package com.cqie.controller;

import com.cqie.dto.caseDto.AddCaseInfoDto;
import com.cqie.entity.CaseInfo;
import com.cqie.exception.SpecialException;
import com.cqie.service.ICaseInfoService;
import com.cqie.util.ResultTemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 病案信息 前端控制器
 * </p>
 *
 * @author 不吃海鲜
 * @since 2024-12-25
 */
@Tag(name = "病例管理Controller", description = "描述：病例接口")
@Slf4j
@RestController
@RequestMapping({"/api/v1.0/caseinfo", "/api/v1/case"})
public class CaseInfoController {

    private final ICaseInfoService caseInfoService;

    public CaseInfoController(ICaseInfoService caseInfoService) {
        this.caseInfoService = caseInfoService;
    }


    @Operation(summary = "新增病例")
    @PostMapping("/addCaseInfo")
    public ResultTemplate<Boolean> addCaseInfo(@RequestBody AddCaseInfoDto addCaseInfoDto) throws SpecialException {
        return ResultTemplate.Success(caseInfoService.addCaseInfo(addCaseInfoDto));
    }

    @Operation(summary = "查询病例")
    @Parameters({
            @Parameter(name = "likeQuery", description = "模糊查询条件"),
            @Parameter(name = "departmentName", description = "科室名称"),
            @Parameter(name = "pageSize", description = "分页大小"),
            @Parameter(name = "pageIndex", description = "页码")
    })
    @GetMapping("/getCaseInfo")
    public ResultTemplate<List<CaseInfo>> getCaseInfo(@RequestParam(defaultValue = "",required = false) String likeQuery,
                                                      @RequestParam(defaultValue = "",required = false) String departmentName,
                                                      @RequestParam(defaultValue = "6",required = false) Integer pageSize,
                                                      @RequestParam(defaultValue = "1",required = false) Integer pageIndex)
            throws SpecialException {
        return ResultTemplate.Success(caseInfoService.getCaseInfo(likeQuery,departmentName,pageSize,pageIndex));
    }

    @Operation(summary = "作废病例")
    @GetMapping("/deleteCaseInfo")
    public ResultTemplate<Boolean> deleteCaseInfo(@RequestParam String caseCode) throws SpecialException {
        return ResultTemplate.Success(caseInfoService.deleteCaseInfo(caseCode));
    }
}
